package com.csi.dao.impl;

import com.csi.dao.InformationDao;
import com.csi.domain.Information;
import com.csi.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class InformationDaoImpl extends JDBCUtils implements InformationDao {
    @Override
    public Information findAll() throws SQLException {
        final  String sql="select*from hotel_information";
        Connection connection = this.getConnection();
        PreparedStatement ps = connection.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        Information information=null;
        if (rs.next()){
            information=new Information();
            information.setHotelIcon(rs.getString("hotelicon"));
            information.setHotelId(rs.getInt("HotelId"));
            information.setHotelName(rs.getString("HotelName"));
            information.setHotelIntroduce(rs.getString("HotelIntroduce"));
        }
        this.release(rs,ps,connection);
        return information;
    }



    @Override
    public int update(Information information) throws SQLException {
        final  String sql="update hotel_information set hotelicon=?,HotelName=?,HotelIntroduce=? where HotelId=?";
        Connection connection = this.getConnection();
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1,information.getHotelIcon());
        ps.setString(2,information.getHotelName());
        ps.setString(3,information.getHotelIntroduce());
        ps.setInt(4,information.getHotelId());
        int i = ps.executeUpdate();
        this.release(ps,connection);
        return i;
    }
}
